package com.example.administrator.jingpingou.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.bean.Shop_Data;
import com.example.administrator.jingpingou.shop_activity.ShopContentActivity;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29 0029.
 */
public class ShopDataAdapterTwo extends RecyclerView.Adapter<ShopDataAdapterTwo.MyViewHolder> {
    private List<Shop_Data.ListYan> mData;
    private Context mContext;
    private ImageOptions options;


    private View mHeaderView;
    private String num_iid;

    public ShopDataAdapterTwo(List<Shop_Data.ListYan> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
        options=new ImageOptions.Builder()
                .setAutoRotate(true)
                .build();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tejia_two, null);
        MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        Shop_Data.ListYan listYan = mData.get(position);

        holder.tvTitle.setText(listYan.getTitle());
        holder.tvZhe.setText(listYan.getDiscount()+"折");
        holder.tvPrice.setText("￥"+listYan.getNow_price());
        holder.tvFPrice.setText("￥"+listYan.getOrigin_price());
        x.image().bind(holder.ivTitle,listYan.getPic_url());

        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Shop_Data.ListYan listYan = mData.get(position);
                num_iid = listYan.getNum_iid();
                Intent intent = new Intent(mContext,ShopContentActivity.class);
                intent.putExtra("path", num_iid);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tvPrice,tvFPrice,tvTitle,tvZhe;
        private ImageView ivTitle;
        private View mView;
        public MyViewHolder(View itemView) {
            super(itemView);
            tvTitle= (TextView) itemView.findViewById(R.id.tv_item_tejia2_title);
            tvPrice= (TextView) itemView.findViewById(R.id.tv_item_tejia2_price);
            tvFPrice= (TextView) itemView.findViewById(R.id.tv_item_tejia2_fprice);
            tvZhe= (TextView) itemView.findViewById(R.id.tv_item_tejia2_zhe);
            mView = itemView.findViewById(R.id.view_item_tejia2_content);
            ivTitle= (ImageView) itemView.findViewById(R.id.iv_item_tejia2_title);
        }
    }
//
}
